<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateSuppliersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('suppliers', function (Blueprint $table) {
            $table->id();
            $table->char('numbering', 6)->default('')->unique()->comment('编号');
            $table->char('name', 32)->default('')->comment('名称');
            $table->char('contact', 16)->default('')->comment('联系人');
            $table->char('phone', 11)->default('')->comment('手机号');
            $table->string('password')->default('')->comment('密码');
            $table->string('emergency_contact')->default('')->comment('紧急联系人');
            $table->string('emergency_phone')->default('')->comment('紧急手机号');

            $table->char('province', 16)->default('')->comment('省(联系地址)');
            $table->char('city', 16)->default('')->comment('市(联系地址)');
            $table->char('area', 16)->default('')->comment('区(联系地址)');
            $table->string('address')->default('')->comment('详细地址(联系地址)');

            $table->char('return_province', 16)->default('')->comment('省(退货地址)');
            $table->char('return_city', 16)->default('')->comment('市(退货地址)');
            $table->char('return_area', 16)->default('')->comment('区(退货地址)');
            $table->string('return_address')->default('')->comment('详细地址(退货地址)');

            $table->string('business_license')->default('')->comment('营业执照');
            $table->tinyInteger('nature')->default(1)->comment('供应商性质; 1:工厂 2:经销商');
            $table->tinyInteger('business_scope')->default(1)->comment('经营范围');
            $table->tinyInteger('delivery_time')->default(1)->comment('发货时效');
            $table->tinyInteger('settlement_method')->default(1)->comment('结算方式; 1:线上 2:线下');
            $table->string('collection_account')->default('')->comment('收款账号');
            $table->tinyInteger('support_invoicing')->default(1)->comment('是否支持开票; 1:支持 2:不支持');

            $table->tinyInteger('status')->default(1)->comment('状态; 1:正常 2:封禁');
            $table->timestamps();
            $table->softDeletes();

            $table->index(['province', 'city', 'area']);
            $table->index('created_at');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('suppliers');
    }
}
